import React from 'react';
import { AutoComplete } from 'antd';
import PropTypes from 'prop-types';
import moment from 'moment';

export const getDataSource = step => {
    const begin = moment('00:00', 'HH:mm');
    const dataSource = [begin.format('HH:mm')];
    while (begin < moment('24:00', 'HH:mm').subtract(step, 'm')) {
        dataSource.push(begin.add(step, 'm').format('HH:mm'));
    }
    return dataSource;
};

const Time = ({ step, ...rest }) => <AutoComplete dataSource={getDataSource(step)} {...rest} />;

Time.propTypes = {
    // 间隔
    step: PropTypes.number
};

Time.defaultProps = {
    step: 15
};

export default Time;
